﻿using ESMAM.DAL.SYS;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ESMAM.BLL.SYS
{
    public class WordBLL
    {
        private static WordDAL dalword = new WordDAL();
        public static Retful GetPager(NameValueCollection form)
        {
            Pager pager = null;
            try
            {
                pager = dalword.GetPager(new ReqParam(form));
            }
            catch (Exception ex)
            {
                return Retful.CreateFail(ex.Message);
            }
            return Retful.CreateSuccess(pager);
        }

        public static Retful Upsert(NameValueCollection form)
        {
            try
            {
                var kv = dalword.Upsert(form);

                return Retful.CreateRetful(kv.Key ? 1 : -1, kv.Value);
            }
            catch (Exception ex)
            {
                return Retful.CreateFail(ex.Message);
            }
        }

        public static Retful Delete(string id)
        {
            bool isOk = false;
            try
            {
                isOk = dalword.Delete(id);
                if (!isOk)
                {
                    return Retful.CreateFail("未知原因，更新失败！");
                }
            }
            catch (Exception ex)
            {
                return Retful.CreateFail(ex.Message);
            }
            return Retful.CreateSuccess(null, "删除成功！");
        }
    }
}
